<template>
  <el-card class="category-selector">
    <el-form inline class="category-selector-form">
      <el-form-item label="一级分类">
        <el-select
          placeholder="请选择分类"
          :value="category1Id"
          @change="getCategory2List"
          :disabled="disabled"
        >
          <el-option
            v-for="c1 in category1List"
            :key="c1.id"
            :value="c1.id"
            :label="c1.name"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select
          placeholder="请选择分类"
          :value="category2Id"
          @change="getCategory3List"
					:disabled="disabled"
        >
          <el-option
            v-for="c2 in category2List"
            :key="c2.id"
            :value="c2.id"
            :label="c2.name"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select
          placeholder="请选择分类"
          :value="category3Id"
          @change="setCategory3Id"
          :disabled="disabled"
				>
          <el-option
            v-for="c3 in category3List"
            :key="c3.id"
            :value="c3.id"
            :label="c3.name"
          >
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
import { mapState, mapActions, mapMutations } from "vuex";
export default {
  name: "CategorySelector",
	props:{
		disabled:{
			type:Boolean,
			required:true
		}
	},
  computed: {
    ...mapState({
      category1Id: (state) => state.category.category1Id,
      category2Id: (state) => state.category.category2Id,
      category3Id: (state) => state.category.category3Id,
      category1List: (state) => state.category.category1List,
      category2List: (state) => state.category.category2List,
      category3List: (state) => state.category.category3List,
    }),
  },
  methods: {
    ...mapActions([
      "category/getCategory1List",
      "category/getCategory2List",
      "category/getCategory3List",
    ]),
    ...mapMutations(["category/SET_CATEGORY3_ID"]),
    getCategory2List(category1Id) {
      this["category/getCategory2List"](category1Id);
    },
    getCategory3List(category2Id) {
      this["category/getCategory3List"](category2Id);
    },
    setCategory3Id(category3Id) {
      this["category/SET_CATEGORY3_ID"](category3Id);
    },
  },
  mounted() {
    this["category/getCategory1List"]();
  },
};
</script>

<style lang="less" scoped>
</style>
